﻿using System;
using Fuse8.DomainFramework.Domain;
using Fuse8.GlobalizationFramework.DataAccess.SqlRepository;

namespace Fuse8.GlobalizationFramework.Domain.Commands
{
    /// <summary>
    /// Default realization of <see cref="IResourceCommandFactory"/>
    /// </summary>
    public class ResourceCommandFactory : IResourceCommandFactory
    {
        /// <summary>
        /// Resturns SQL commands
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        public virtual T GetCommand<T>() where T : class, IEntityCommand<Resource>
        {
            if (typeof(T).Equals(typeof(ResourceByKeyAndLocale)))
            {
                return new ResourceByKeyAndLocaleSqlCommand() as T;
            }

            if (typeof(T).Equals(typeof(ResourceSelectAllByLocale)))
            {
                return new ResourceSelectAllByLocaleSqlCommand() as T;
            }

            throw new NotSupportedException("Specfied type is not supported by factory");
        }
    }
}